/**
 * 
 */
package com.cqcis.uip.base.framework.core.config.impl;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.cqcis.uip.base.framework.core.config.PropertiesRepositoryService;

/**
 * 属性配置管理, 维护需要属性配置的包, 属性配置路径与包名的关系
 * 
 * @author huangmy
 * @date 2008-2-16
 */
public class PropertiesRepositoryServiceImpl implements PropertiesRepositoryService {	
	// bundleLocation 包路径
	// propertiesLocation 属性配置文件路径*/
	private Map<String, List<String>> repository = new ConcurrentHashMap<String, List<String>>();
	private Map<String, String> propertiesRepository = new ConcurrentHashMap<String, String>();
	
	/**
	 * 根据bundle路径获取属性配置路径
	 * @param bundleLocation
	 * @return
	 */
	public List<String> getPropertiesLocations(String bundleLocation) {
		return repository.get(bundleLocation);
	}
	
	/**
	 * 根据属性配置文件路径获取属性配置路径
	 * @param propertiesLocation
	 * @return
	 */
	public String getBundleLocation(String propertiesLocation) {
		return propertiesRepository.get(propertiesLocation);
	}
	
	/**
	 * 增加属性配置
	 * @param bundleLocation
	 * @param propertiesLocation
	 * @return
	 */
	public void put(String bundleLocation, List<String> propertiesLocations) {		
		repository.put(bundleLocation, propertiesLocations);
		for (String propertiesLocation : propertiesLocations) {
			propertiesRepository.put(propertiesLocation, bundleLocation);
		}		
	}
	
	/**
	 * 删除指定bundle路径的属性配置
	 * @param bundleLocation
	 * @return
	 */
	public void removeByBundleLocation(String bundleLocation) {
		List<String> propertiesLocations = repository.remove(bundleLocation);		
		if (propertiesLocations != null) {
			for (String propertiesLocation : propertiesLocations) {
				propertiesRepository.remove(propertiesLocation);
			}
		}
	}
	
	/**
	 * 删除指定配置文件路径的属性配置
	 * @param propertiesLocation
	 */
	public void removeByPropertiesLocation(String propertiesLocation) {
		String bundleLocation = propertiesRepository.remove(propertiesLocation);		
		if (bundleLocation != null) {
			repository.remove(bundleLocation);
		}
	}
}
